package com.company.gas.controller;

import com.company.gas.pojo.Customer;
import com.company.gas.service.ICustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/customer")
@Api(tags = "客户管理相关接口")
public class CustomerController {

    @Autowired
    private ICustomerService iCustomerService;

    //查询全部客户
    @GetMapping("/queryCustomerList")
    @ApiOperation("查询全部客户")
    public List<Customer> queryCustomerList(){
        List<Customer> customerList = iCustomerService.queryCustomerList();
        return customerList;
    }
    //根据客户ID查询客户
    @GetMapping("/queryCustomerById")
    @ApiOperation("根据ID查询指定客户")
    public Customer queryCustomerById(@RequestParam(value = "客户ID") String cusId) {
        Customer customer = iCustomerService.queryCustomerById(cusId);
        System.out.println(customer);
        return customer;
    }

    //添加一位客户
    @GetMapping("/addCustomer")
    @ApiOperation("添加一位客户")
    public String addCustomer(@RequestParam(value = "客户ID") String cusId, @RequestParam(value = "客户姓名") String cusName,
                              @RequestParam(value = "客户电话") String cusPhnum,
                              @RequestParam(value = "客户地址") String cusAdr,
                              @RequestParam(value = "标识符") Integer flag,
                              @RequestParam(value = "创建时间") Date createTime, @RequestParam(value = "创建人") String createBy,
                              @RequestParam(value = "修改时间") Date modifyTime, @RequestParam(value = "修改人") String modifyBy) {
        int isAddCustomer = iCustomerService.addCustomer(cusId,cusName,cusPhnum,cusAdr,flag,createTime,createBy,modifyTime,modifyBy);
        if(isAddCustomer == 1){
            return "add success";
        }else {
            return "add fail";
        }
    }

    //修改客户信息
    @GetMapping("/updateCustomer")
    @ApiOperation("修改客户信息")
    public String updateCustomer(@RequestParam(value = "客户ID") String cusId, @RequestParam(value = "客户姓名") String cusName,
                                 @RequestParam(value = "客户电话") String cusPhnum,
                                 @RequestParam(value = "客户地址") String cusAdr,
                                 @RequestParam(value = "标识符") Integer flag,
                                 @RequestParam(value = "修改时间") Date modifyTime, @RequestParam(value = "修改人") String modifyBy){
        int isUpdateCustomer = iCustomerService.updateCustomer(cusId,cusName,cusPhnum,cusAdr,flag,modifyTime,modifyBy);
        if(isUpdateCustomer== 1){
            return "update success";
        }else {
            return "update fail";
        }
    }

    //删除指定ID客户
    @GetMapping("/deleteCustomer")
    @ApiOperation("删除指定ID的客户")
    public String deleteCustomer(@RequestParam(value = "客户ID") String cusId){
        int isDeleteCustomer = iCustomerService.deleteCustomer(cusId);
        if(isDeleteCustomer == 1){
            return "delete success";
        }else {
            return "delete fail";
        }
    }


}
